// antd 按需加载
import { Toast, Portal } from '@ant-design/react-native';
import axios from 'axios'

import store from '../../../store/store.js'
import * as ActionTypes from '../../../constants/constants.js'
import { isUser, isWxUser, path, saveData, loadData, removeData } from '../../../util/utils.js'
import request from '../../../api/request.js'

export async function billboard(options) {
    const { dispatch } = this.props
    const res = await request.HomeController.billboard(options)
    console.log(res)
    if (res.status == 502) {
        dispatch({
            type: ActionTypes.billboardError,
            data: res
        })
        return
    }
    dispatch({
        type: ActionTypes.billboard,
        data: res.data.data
    })
}

export async function goodsNew(options) {
    const { dispatch } = this.props
    const { refresh } = options
    const loading = Toast.loading('加载中', 0, null, false)
    const res = await request.GoodsController.goodsNew(options)
    Portal.remove(loading)
    console.log(res)
    if (res.error) {
        dispatch({
            type: ActionTypes.goodsNewError,
            data: res
        })
        return
    }
    if (refresh) {
        dispatch({
            type: ActionTypes.goodsNewRefresh,
            data: res.data.data
        })
    } else {
        dispatch({
            type: ActionTypes.goodsNew,
            data: res.data.data
        })
    }
}

